package br.fbc.action;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;
import org.json.JSONObject;

import com.google.code.facebookapi.FacebookJsonRestClient;
import com.google.code.facebookapi.FacebookWebappHelper;

/**
 * Incluir photo no mural
 * @author frederico.concrete *
 */
public class IncluirPhotoAction extends ImageAction {
	
	
	
	public static final String API_KEY="";
	private final String SECRET_KEY="";
	private FacebookJsonRestClient facebookClient;
	private FacebookWebappHelper<Object> facebookAppHelp;
	private HttpServletRequest request;
	private HttpServletResponse response;
	private String nome;
	
	public String execute() throws Exception{
		
		request = getRequest();
		request.getParameter("fb_sig_user");
		
		List<Long> listUids = new ArrayList<Long>();
		listUids.add(Long.valueOf(request.getParameter("fb_sig_user")));
		Set<CharSequence> listFields = new HashSet<CharSequence>();
		listFields.add("name");
		
		facebookAppHelp = FacebookWebappHelper.newInstanceJson(request, response, API_KEY, SECRET_KEY);
		facebookClient = (FacebookJsonRestClient) facebookAppHelp.getFacebookRestClient();
		
		JSONArray result = facebookClient.users_getInfo(listUids, listFields);
		
		if ( result != null ){
			JSONObject object = result.getJSONObject(0);
			nome = object.getString("name");
		}
		
		
		 
		
		
		
		
		return SUCCESS;
		
		
	}

	public String getNome() {
		return nome;
	}

}
